package com.yimi.yinhepda.adapter.unload_offline;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.yimi.yinhepda.R;
import com.yimi.yinhepda.db.table.LineVoTable;

import java.util.List;

/**
 * 卸车上一站查询适配adapter
 */
public class UnLoadPreStationQueryAdapter extends BaseAdapter {
  LayoutInflater inflater;
  List<LineVoTable> dataList;

  public UnLoadPreStationQueryAdapter(Context context, List<LineVoTable> dataList) {
    this.dataList = dataList;
    this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }

  @Override public int getCount() {
    return null != dataList ? dataList.size() : 0;
  }

  @Override public View getView(int position, View convertView, ViewGroup arg2) {
    ViewHolder holder = null;
    if (convertView == null) {
      holder = new ViewHolder();
      convertView = inflater.inflate(R.layout.unload_pre_station_item, null);
      holder.lineCode = (TextView) convertView.findViewById(R.id.tv_line_code);
      holder.lineName = (TextView) convertView.findViewById(R.id.tv_line_name);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    LineVoTable lineVoTable = dataList.get(position);
    holder.lineCode.setText(lineVoTable.getDestZoneCode());
    holder.lineName.setText(lineVoTable.getDestZoneName());

    return convertView;
  }

  static class ViewHolder {
    TextView lineCode;
    TextView lineName;
  }

  @Override public Object getItem(int position) {
    return dataList.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }
}
